//
//  ContactViewController.m
//  Tiger
//
//  Created by King on 11-9-19.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ContactViewController.h"
#import "MapViewController.h"

@implementation ContactViewController

-(id) init
{
    if (self = [super init]) {
        NSDictionary* tStrDic0 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"上虎（上海）精密工具有限公司",@"title",
                                  @"地址：上海市闵行区华漕镇联友路669号\r\n"
                                  "Tel:021—52264911\r\n"
                                  "Fax:021—52264919\r\n",@"gray",
                                  nil];
        NSDictionary* tStrDic1 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"昆山陸虎數控刀具商行",@"title",
                                  @"地址：江蘇省昆山市玉山鎮昆北路709號\r\n"
                                  "電話：0512-50391902\r\n"
                                  "傳真：0512-50391903\r\n",@"gray",
                                  nil];
        NSDictionary* tStrDic2 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"揚州山特數控機具有限公司",@"title",
                                  @"公司地址：江蘇省揚州市潤揚廣場3棟201\r\n"
                                  "電話：0514-82066968\r\n"
                                  "傳真：0514-85062011\r\n",@"gray",
                                  nil];
        NSDictionary* tStrDic3 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"日升數控刀具有限公司",@"title",
                                  @"公司地址：浙江省余姚市輕工模具城金昌路402-404號\r\n"
                                  "電話：0574-62634391\r\n"
                                  "傳真：0574-62639791\r\n",@"gray",
                                  nil];
        NSDictionary* tStrDic4 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"大連恒煜机械设备有限公司",@"title",
                                  @"公司地址：大连开发区金玛商城五楼25号\r\n"
                                  "電話：0411-66778936\r\n"
                                  "傳真：0411-66778926\r\n",@"gray",
                                  nil];
        NSDictionary* tStrDic5 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"歐德萊企業集團有限公司",@"title",
                                  @"公司地址：深圳市寶安區沙井鎮中心路星河大廈609\r\n"
                                  "電話：0755-81760088\r\n"
                                  "傳真：0755-81760086\r\n",@"gray",
                                  nil];
        NSDictionary* tStrDic6 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"陝西信豐機電技術有限公司",@"title",
                                  @"公司地址：西安市高新開發區科技一路17號\r\n"
                                  "電話：029-88142922\r\n"
                                  "傳真：029-87938715\r\n",@"gray",
                                  nil];
        NSDictionary* tStrDic7 = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"成都真穎精工機電設備有限公司",@"title",
                                  @"公司地址：成都市成華區建設北路三段11號東方明珠花園西區10-1-15號\r\n"
                                  "電話：028-83264548\r\n"
                                  "傳真：028-86799252\r\n",@"gray",
                                  nil];
        p_StrListData = [[NSMutableArray alloc] initWithObjects:
                         tStrDic0,tStrDic1,
                         tStrDic2,tStrDic3,
                         tStrDic4,tStrDic5,
                         tStrDic6,tStrDic7,
                         nil];
    }
    return self;
}

- (void)dealloc {
    [p_ContactTableView release];
    [super dealloc];
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView*  tBGImgView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"screen_bg.png"]];
    tBGImgView.frame =CGRectMake(0, 0, 320, 480-88);
    p_ContactTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320,480-88) style:UITableViewStylePlain];
    p_ContactTableView.separatorColor = [UIColor darkGrayColor];
    [p_ContactTableView setBackgroundView:tBGImgView];
    [tBGImgView release];
    
    UIView* tHeaderContent = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
    UIImageView*  tHeaderImgView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
    tHeaderImgView.frame =CGRectMake(40, 12, 240, 100);
    [tHeaderContent addSubview:tHeaderImgView];
    [tHeaderImgView release];
    p_ContactTableView.tableHeaderView = tHeaderContent;
    [tHeaderContent release];
    p_ContactTableView.delegate =self;
    p_ContactTableView.dataSource = self;
    [self.view addSubview:p_ContactTableView];
}


- (void)mapButtonTapped:(UIButton*)sender{
    int tMapIndex = sender.tag-0x100;
	MapViewController *viewController = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
	viewController.hidesBottomBarWhenPushed = YES;
	UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
								   initWithTitle:@"联系我们" 
								   style:UIBarButtonItemStylePlain 
								   target:self
								   action:nil];
	self.navigationItem.backBarButtonItem = backButton;
	//导航自带的动画
	[self.navigationController pushViewController:viewController animated:YES];
	[viewController release];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
	
}
#pragma mark-
#pragma mark UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 140;
}
#pragma mark-
#pragma mark UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString* s_CellContact =@"cellcontact";
    UITableViewCell* tCell = [tableView dequeueReusableCellWithIdentifier:s_CellContact];
    if (tCell == nil) {
        tCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:s_CellContact];
        tCell.selectionStyle = UITableViewCellSelectionStyleNone;
        UIButton* tMapBtt = [UIButton buttonWithType:UIButtonTypeCustom];
        [tMapBtt setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"button1.png"]]];
        [tMapBtt setTitle:@"地 图" forState:UIControlStateNormal];
        [tMapBtt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        tMapBtt.tag =0x100;
        tMapBtt.frame =CGRectMake(200, 100, 78, 30);
        [tMapBtt addTarget:self action:@selector(mapButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        [tCell addSubview:tMapBtt];
        
        UILabel* tTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(40, 10, 240, 20)];
        tTitleLab.tag =10;
        [tTitleLab setBackgroundColor:[UIColor clearColor]];
        [tTitleLab setFont:[UIFont boldSystemFontOfSize:14.f]];
        [tTitleLab setTextColor:[UIColor whiteColor]];
        [tCell addSubview:tTitleLab];
        [tTitleLab release];
        
        
        UILabel* tContentLab = [[UILabel alloc] initWithFrame:CGRectMake(40, 34, 240, 80)];
        tContentLab.tag =11;
        [tContentLab setBackgroundColor:[UIColor clearColor]];
        tContentLab.numberOfLines =10;
        [tContentLab setFont:[UIFont systemFontOfSize:13.f]];
        [tContentLab setTextColor:[UIColor lightGrayColor]];
        [tCell addSubview:tContentLab];
        [tContentLab release];
    }
    NSDictionary* tRowDic = [p_StrListData objectAtIndex:indexPath.row];
    UILabel* tTitleLab = (UILabel*)[tCell viewWithTag:10];
    tTitleLab.text =[tRowDic objectForKey:@"title"];
    UILabel* tContentLab = (UILabel*)[tCell viewWithTag:11];
    tContentLab.text =[tRowDic objectForKey:@"gray"];
    UIButton* tMapBtt = (UIButton*)[self.view viewWithTag:0x100];
    tMapBtt.tag =0x100+indexPath.row;
    return tCell;
}
@end
